unit uWindowOption;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, Grids, DBGridEh, StdCtrls, ImageTools;

type
  TfWindowOption = class(TForm)
    GroupBox1: TGroupBox;
    DBGridEh1: TDBGridEh;
    tbWindowOption: TToolBar;
    tbAddWindowOption: TToolButton;
    tbDelWindowOption: TToolButton;
    procedure tbAddWindowOptionClick(Sender: TObject);
    procedure tbDelWindowOptionClick(Sender: TObject);
    procedure DBGridEh1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
    procedure DBGridEh1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fWindowOption: TfWindowOption;

implementation

uses uDBData, uAddWindowOption;

{$R *.dfm}

procedure TfWindowOption.tbAddWindowOptionClick(Sender: TObject);
begin
  fAddWindowOption.ShowModal();
end;

procedure TfWindowOption.tbDelWindowOptionClick(Sender: TObject);
begin
  fDBData.DeleteRecord(fDBData.dWindowOption);
end;

procedure TfWindowOption.DBGridEh1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumnEh;
  State: TGridDrawState);
var mybitmap: TBitmap;
begin
  if(Column.Index = 1) then
  begin
    mybitmap := TBitmap.Create;
    mybitmap.Assign(HImageTools.GetBitmap(fDBData.dWindowOption, 'OptionImage'));
    mybitmap.TransparentColor := clFuchsia;
    mybitmap.Transparent := True;
    (Sender as TDBGridEh).Canvas.Draw(Rect.Left+(Round(Column.Width/2)-(Round(mybitmap.Width/2))), Rect.Top+(Round((Sender as TDBGridEh).RowHeight/2)-(Round(mybitmap.Height/2))), mybitmap);
    mybitmap.Free;
  end;
end;

procedure TfWindowOption.DBGridEh1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then (Sender as TDBGridEh).DataSource.DataSet.Post;
end;

end.
